package com.it.service;
import com.it.bean.Staff;
import com.it.data.StaffData;

import java.util.Random;
import java.util.Scanner;
public class StaffService {
    private Staff[] staffs;
    private int length;
    public int menu() {
        System.out.println
                       ("--------1 添加员工-------------\n" +
                        "--------2 查看所有员工-------------\n" +
                        "--------3 按照编号查看单个员工-------\n" +
                        "--------4 按照员工编号删除员工-------\n" +
                        "--------5 抽奖出一名中奖员工--------------\n" +
                        "--------6 查看该公司员工所有工资的总和-------\n" +
                        "--------7 查看该公司员工的平均工资----------\n" +
                        "--------8 查看该公司薪资最高员工的工资----------\n" +
                        "--------9 查看该公司薪资最低员工的工资----------\n" +
                        "--------10 查看该公司薪资高于平均工资的员工信息-----\n" +
                        "--------0 退出系统--------------\n");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入功能号:");
        int num = scanner.nextInt();
        return num;
    }

    public void addStaff(Object staff) {
        for (int i = 0; i < 5; i++){

    }

  //  public void findAllStaf {
    }
   /* public void addStaff(Staff staff) {
        Staff[] staffs = new Staff[3];
        for (int i = 0; i <3 ; i++) {
            if (staffs[i] == null) {
                staffs[i] = staff;
                System.out.println("添加成功");
                return;
            }
        }
        System.out.println("添加失败");
    }

    public void findAllStaff() {
        for (Staff staff : staffs){
            if (staffs != null) {
                System.out.println(staff);
            }else {
                System.out.println("员工不存在");
            }
        }
    }

    public void findStaffByName(String staffname) {
        for (int i = 0; i < length; i++) {
            if (staffs[i].getStaffname().equals(staffname)) {
                System.out.println(staffs[i]);
            } else {
                System.out.println("该员工不存在");
                return;
            }
        }
    }

    public void delStaff(int staffidnum) {
        for (int i = 0; i < length; i++) {
            if (staffs[i].getStaffidnum().equals(staffidnum)) {
                for (int j = i; j < length - 1; j++) {
                    staffs[j] = staffs[j + 1];
                }
                length--;
                System.out.println("删除成功");
            } else {
                System.out.println("该员工不存在");
                return;
            }
        }
    }

    public void jpUser() {
        Random random = new Random();
        //产生下标
        int index = random.nextInt(staffs.length);
        //判断该用户是否为null
        if (staffs[index] == null) {
            jpUser();//递归调用
        } else {
            System.out.println("恭喜" + staffs[index].getStaffname() + "中奖了！");
        }
    }

    public void sumSalary() {
        int sum = 0;
        for (int i = 0; i < length; i++) {
            sum += Integer.parseInt(staffs[i].getStaffsalary());
        }
        System.out.println("公司员工工资总和为：" + sum);
    }

    public void avgSalary() {
        int sum = 0;
        for (int i = 0; i < length; i++) {
            sum += Integer.parseInt(staffs[i].getStaffsalary());
            System.out.println("公司员工平均工资为：" + sum / length);
            return;
        }
    }

    public void maxSalary() {
        int max = 0;
        for (int i = 0; i < length; i++) {
            if (Integer.parseInt(staffs[i].getStaffsalary()) > max) {
                max = Integer.parseInt(staffs[i].getStaffsalary());
                System.out.println("公司员工薪资最高为：" + max);
            }
        }
    }
    public void minSalary() {
        int min = 0;
        for (int i = 0; i < length; i++) {
            if (Integer.parseInt(staffs[i].getStaffsalary()) < min) {
                min = Integer.parseInt(staffs[i].getStaffsalary());
                System.out.println("公司员工薪资最低为：" + min);
                return;
            }
        }
    }
    public void aboveavg() {

    }

    public void addStaff(StaffService staffService, Scanner sc) {
        System.out.println("请输入员工编号");
        String staffidnum = sc.next();
        System.out.println("请输入员工姓名");
        String staffname = sc.next();
        System.out.println("请输入员工年龄");
        String staffage = sc.next();
        System.out.println("请输入员工工资");
        String staffsalary = sc.next();
        Staff staff = new Staff(staffidnum, staffname, staffage, staffsalary);
    }

    public void addStaff(String staffidnum, String staffname, String staffage, String staffsalary) {
    }*/
}}